Skip to content

fix(gateway): send a streamed start failure's error and DONE as two events - #348

Merged
T-Crypt merged 1 commit into
mainfrom
T-Crypt/sse-error-event
Nov 16, 2026
Merged

T-Crypt merged 1 commit into
mainfrom
T-Crypt/sse-error-event

Conversation

@T-Crypt

@T-Crypt T-Crypt commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Closes #346.

What changes

When a streamed request's engine never came up, sseFailure wrote data: {error}\ndata: [DONE]\n\n. That is one server-sent event with two data lines. An SSE client joins the data lines of an event with a newline, so it got the error object followed by [DONE], could not parse it, and reported "malformed server-sent event JSON" with no reason.

A blank line now ends the error event before [DONE], so the client gets two events. The first is the OpenAI-shaped error object, which already names the reason, for example strata got no berth: ... held by strata-sc117 [foreground, active].

Proof

  • TestKeepAliveFailureEmitsErrorEvent now parses the stream the way an SSE client does and requires each event's data to be JSON or [DONE]. Without the fix it fails with the joined {...}\n[DONE] data.
  • Full proof is green: build, gofmt, vet, go test ./..., the Windows build and vet, golangci-lint 2.14.0.

…vents

sseFailure wrote "data: {error}\ndata: [DONE]\n\n", one SSE event with two
data lines. A client joins those lines with a newline, so it read the
error object followed by "[DONE]", failed to parse it and reported
"malformed server-sent event JSON" with no reason. A blank line now ends
the error event before DONE.

TestKeepAliveFailureEmitsErrorEvent reads the stream the way an SSE
client does and requires each event's data to be JSON or [DONE].

Closes #346
@T-Crypt
T-Crypt merged commit 326229a into main Nov 16, 2026
2 checks passed
@T-Crypt
T-Crypt deleted the T-Crypt/sse-error-event branch November 16, 2026 14:47
T-Crypt added a commit that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway: a streamed request it gives up on should end with a readable error, not a cut stream

1 participant